HEX
Server: Apache/2.4.68 (Debian)
System: Linux as-cs-widget-demo-us-central1 6.1.0-44-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.164-1 (2026-03-09) x86_64
User: root (0)
PHP: 8.2.32
Disabled: NONE
Upload Files
File: /var/www/kevin-demo/wp-content/plugins/grocerslist/includes/Support/LinkExtractor.php
<?php

namespace GrocersList\Support;

class LinkExtractor
{
    static function extract(string $content): array
    {
        preg_match_all(Regex::amazonLink(), $content, $hrefMatches);
        $hrefLinks = $hrefMatches[1] ?? [];

        preg_match_all(Regex::amazonLinkWithDataAttribute(), $content, $dataMatches);
        $dataLinks = $dataMatches[1] ?? [];

        return array_unique(array_merge($hrefLinks, $dataLinks));
    }

    static function extractUnrewrittenLinks(string $content): array
    {
        preg_match_all(Regex::amazonLink(), $content, $allMatches, PREG_SET_ORDER);

        $unrewrittenLinks = [];

        foreach ($allMatches as $match) {
            $fullTag = $match[0];
            $url = $match[1];

            if (strpos($fullTag, 'data-grocerslist-rewritten-link') === false) {
                $unrewrittenLinks[] = $url;
            }
        }

        return $unrewrittenLinks;
    }
}